<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/4/11
 * Time: 9:52
 */

namespace Admin\Controller;
use Admin\Api\MemberApi;
use Bbs\Api\BbsMemberApi;
use Bbs\Api\CoreReportApi;
use Bbs\Api\ForumUserAdmingroupApi;

class BbsMemberController extends AdminController{

    /**
     * 禁言管理
     */
    public function banUser(){
        //判断是否有权限
        $result = apiCall(BbsMemberApi::GET_INFO,array(array('id'=>UID)));
        $allowbanuser = 0;
        if($result['status']){
            $allowbanuser = $result['info']['allowbanuser'];
            $this->assign('allowbanuser',$allowbanuser);
        }else{
            $this -> error($result['info']);
        }
        if($allowbanuser){
            $fid = $result['info']['fid'];
        }

        if(!$allowbanuser){
            $this->display();
            exit();
        }

        $allowpost = I('get.allowpost',1);
        $key = urldecode(I('key','','trim'));
        $where['nickname'] = array('like',"%$key%");
        $where['id'] = $key;
        $where['_logic'] = 'or';

        $map['_complex'] = $where;

        if($allowpost == 0){
            $map['allowpost'] = 1;
        }

        $page = array('curpage' =>  I('get.p',0), 'size' => 15);
        $order = 'id asc';
        $params['key'] = $key;
        $result = apiCall(BbsMemberApi::QUERY,array($map,$page,$order,$params));

        $this->assign('allowpost',$allowpost);

        if ($result['status']) {

            $this -> assign("show", $result['info']['show']);
            $this -> assign("list", $result['info']['list']);
        } else {
            $this -> error($result['info']);
        }

        $this->display();

    }

    /**
     * 禁言
     */
    public function ban(){

        $uid = I('get.uid',-1);
        $allow = I('get.allow',-1);

        if($uid==-1 || $allow==-1){
            $this->error('参数缺失');
        }

        $result = apiCall(ForumUserAdmingroupApi::BAN_USER,array(UID,$uid,$allow));
        if($result['status']){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }

    }

    /**
     * 举报管理
     */
    public function coreReport(){

        $operate = I('get.operate',0);
        $this->assign('operate',$operate);

        $page = array('curpage' =>  I('get.p',0), 'size' => 15);
        $order = 'id desc';

        if($operate==0){
            $map = array(
                'op_time' => 0
            );
        }else{
            $map['op_time'] = array('neq',0);
        }

        $params['operate'] = $operate;

        $result = apiCall(CoreReportApi::QUERY,array($map,$page,$order,$params));
        if($result['status']){
            $this->assign('list',$result['info']['list']);
            $this->assign('show',$result['info']['show']);
        }else{
            $this->error($result['info']);
        }


        $this->display();

    }
    
    /**
     * 举报处理
     */
    public function operateCoreReport(){

        if(IS_POST){
            $id = I('get.id',-1);
            if($id==-1){
                $this->error('参数错误！');
            }

            $op_time = I('post.op_time',time());
            $op_result = I('post.op_result','');

            $result = apiCall(MemberApi::GET_INFO,array(array('uid'=>UID)));

            if($result['status']){
                $op_name = $result['info']['nickname'];
            }else{
                $this->error('异常错误！',U('Admin/BbsMember/coreReport'));
            }

            $entity = array(
                'op_time' => strtotime($op_time),
                'op_result' => $op_result,
                'op_name'=>$op_name
            );
            $result = apiCall(CoreReportApi::SAVE_BY_ID,array($id,$entity));

            if($result['status']){
                $this->success('操作成功!',U('Admin/BbsMember/coreReport'));
            }else{
                $this->error('操作失败!');
            }

        }else{
            $id = I('get.id',-1);
            if($id==-1){
                $this->error('参数错误！',U('Admin/BbsMember/coreReport'));
            }
            $this->display();
        }

    }

}